package com.itcast.java.member.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.itcast.java.common.base.R;
import com.itcast.java.member.config.TestConfig;
import com.itcast.java.member.feign.ICouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 写点什么？
 *
 * @author hrz
 * @since 2020/9/17 0017
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private ICouponService couponService;
    @Autowired
    private TestConfig testConfig;

    @GetMapping("/user/coupons")
    public R<?> userCoupons(@RequestParam("userId") String userId) {
        return couponService.coupons(userId);
    }

    @GetMapping("/user/info")
    @SentinelResource("/test/user/info")
    public R<?> userInfo() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("name", testConfig.getUserName());
        map.put("age", testConfig.getAge());
        return R.ok(map);
    }
}
